package cz.proks.schoolpupilbook.gae.converter;

import com.google.appengine.api.datastore.KeyFactory;

import cz.proks.schoolpupilbook.gae.dbo.CourseDBO;
import cz.proks.schoolpupilbook.shared.domain.Course;
import cz.proks.schoolpupilbook.shared.util.Tester;

public class CourseConverter implements Converter<CourseDBO, Course>{
	@Override	
	public CourseDBO getDBO(Course course) {
		if (course == null)
			return null;
		
		CourseDBO dbo = new CourseDBO();
		
		if (!Tester.isEmpty(course.getId()))
			dbo.setId(KeyFactory.stringToKey(course.getId()));
		
		dbo.setCode(course.getCode());
		dbo.setName(course.getName());
		
		return dbo;
	}
	
	@Override
	public Course getDomain(CourseDBO dbo) {
		if (dbo == null)
			return null;
		
		Course course = new Course();
		course.setId(KeyFactory.keyToString(dbo.getId()));
		course.setCode(dbo.getCode());
		course.setName(dbo.getName());
		
		return course;
	}
}
